package com.hera.base.util;

import javax.naming.InitialContext;
import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component("jdbcTemplateUtil")
public class JdbcTemplateUtil {

	/*@Autowired
	private DataSourceDao datasourceDao;
	
	private static Map<String, DataSource> datasources;
	
	public void cargarDatasource() {
		datasources = new HashMap<String, DataSource>();
		
		List<Datasource> list = datasourceDao.findAll();
		
		for (Datasource datasource : list) {
			new InitialContext();
			//datasource.getJndiName()
		}
	}*/
	public JdbcTemplate getJdbcTemplate(String jdbcName) {
		InitialContext ic = null;
		DataSource dataSource = null;
		try {
			ic = new InitialContext();
			dataSource = (DataSource) ic.lookup(jdbcName);
		} catch (Exception e) {
			throw new RuntimeException();
		}
		return new JdbcTemplate(dataSource);
	}
}
